package com.yipei.business.controller;

import com.yipei.business.domain.MlFlashNews;
import com.yipei.business.service.IMlFlashNewsService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 新闻快讯Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/flashnews")
@Api(tags = "新闻快讯", description = "新闻快讯管理")
public class MlFlashNewsController extends BaseController {
    @Autowired
    private IMlFlashNewsService mlFlashNewsService;

    /**
     * 查询新闻快讯列表
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:list')")
    @ApiOperation("理财产品获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlFlashNews mlFlashNews) throws IOException {
        startPage();
        List<MlFlashNews> list = mlFlashNewsService.selectMlFlashNewsList(mlFlashNews);
        return getDataTable(list);
    }

    /**
     * 导出新闻快讯列表
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:export')")
    @ApiOperation("理财产品导出数据")
    @Log(title = "新闻快讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlFlashNews mlFlashNews) {
        List<MlFlashNews> list = mlFlashNewsService.selectMlFlashNewsList(mlFlashNews);
        ExcelUtil<MlFlashNews> util = new ExcelUtil<MlFlashNews>(MlFlashNews.class);
        util.exportExcel(response, list, "新闻快讯数据");
    }

    /**
     * 获取新闻快讯详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:query')")
    @ApiOperation("理财产品通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlFlashNewsService.selectMlFlashNewsById(id));
    }

    /**
     * 新增新闻快讯
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:add')")
    @ApiOperation("理财产品新增数据")
    @Log(title = "新闻快讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlFlashNews mlFlashNews) {

//       return mlFlashNewsService.saveBatch(Collections.singleton(mlFlashNews));
        return toAjax(mlFlashNewsService.insertMlFlashNews(mlFlashNews));
    }

    /**
     * 修改新闻快讯
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:edit')")
    @ApiOperation("理财产品修改数据")
    @Log(title = "新闻快讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlFlashNews mlFlashNews) {
        return toAjax(mlFlashNewsService.updateMlFlashNews(mlFlashNews));
    }

    /**
     * 删除新闻快讯
     */
    //@PreAuthorize("@ss.hasPermi('business:flashnews:remove')")
    @ApiOperation("理财产品删除数据")
    @Log(title = "新闻快讯", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlFlashNewsService.deleteMlFlashNewsByIds(ids));
    }
}
